package com.bulemobi.activity.ac_user_centre;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bulemobi.net.tsz.afinal.annotation.view.ViewInject;
import com.bulemobi.view.BaseActivity;
import com.jsyh.hcb.R;

/**
 * Created by 武 on 2014/9/22 0022.
 * 我的缴费
 * item已完成
 */
public class Ac_MyPay extends BaseActivity implements View.OnClickListener {
    @ViewInject(id = R.id.sildiing)
    LinearLayout silding;
    @ViewInject(id = R.id.tv_back)
    TextView tv_back;
    @ViewInject(id = R.id.tv_filter)
    TextView tv_filter;
    private boolean isFirstDown = true;
    @ViewInject(id = R.id.vPager)
    ViewPager pager;
    @ViewInject(id = R.id.tv_titleText)
    TextView tv_titleText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_my_pay_mian);
        silding.setVisibility(View.GONE);
        initView();
        initViewPager();
    }

    private void initViewPager() {
        LayoutInflater inflater = getLayoutInflater();
        View thisMonth = inflater.inflate(R.layout.pager_lay_1, null);
        View history = inflater.inflate(R.layout.pager_lay_2, null);
        pager.addView(thisMonth);
        pager.addView(history);
        pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i2) {

            }

            @Override
            public void onPageSelected(int i) {

            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }

    private void initView() {
        tv_titleText.setText("我的缴费");
        tv_back.setOnClickListener(this);
        tv_filter.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //返回
            case R.id.tv_back:
                finish();
                break;
            //筛选按钮
            case R.id.tv_filter:
                setSilding();
                break;
        }
    }

    private void setSilding() {
        if (isFirstDown) {
            Log.d("OnClick", "+++++++++++++");
            silding.setVisibility(View.VISIBLE);
            TranslateAnimation anim = new TranslateAnimation(
                    Animation.RELATIVE_TO_SELF, 1.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f);
//                    anim.setFillAfter(true);
            anim.setDuration(2000);
            anim.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    tv_filter.setEnabled(false);
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    tv_filter.setEnabled(true);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
            silding.startAnimation(anim);
            isFirstDown = false;
        } else {
            Log.d("OnClick", "_________________");
            silding.setVisibility(View.GONE);
            TranslateAnimation anim = new TranslateAnimation(
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 1.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 0.0f);
//                    anim.setFillAfter(true);
            anim.setDuration(2000);
            anim.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    tv_filter.setEnabled(false);
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    tv_filter.setEnabled(true);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
            silding.startAnimation(anim);
            isFirstDown = true;
        }
    }
}
